package com.blockchain.securewallet.tools;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Lopez on 2018/5/30.
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {

    private int space;
    private boolean isHasExcision;

    public SpaceItemDecoration(int space) {
        this.space = space;
    }

    /**
     * 是否拥有上下的分割线
     *
     * @param space
     * @param isHasExcision
     */
    public SpaceItemDecoration(int space, boolean isHasExcision) {
        this.space = space;
        this.isHasExcision = isHasExcision;
    }


    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        //parent.getAdapter().getItemCount()
        int position = parent.getChildAdapterPosition(view);

        if (isHasExcision) {
            //给多账户管理的上下分割线使用
            outRect.top = 0;
            outRect.left = 0;
            outRect.right = 0;
            outRect.bottom = space;

        } else {
            //默认给12宫格的使用
            outRect.top = space;
            outRect.left = space;
            outRect.right = 0;
            outRect.bottom = 0;
        }

        /*//除了第一行不设置顶部间距
        if (!(position == 0 || position == 1 || position == 2)) {
            outRect.top = space;
        }

        //除了第一列不设置左边间距
        if (!(position % 3 == 0)) {
            outRect.left = space;
        }*/

       /* //除了最后1列不设置右边间距
        if (!(position == 2 || position == 5 || position == 8 || position == 11)) {
            outRect.right = space;
        }*/

        /*//除了最后1行不设置底部间距
        if (!(position == 9 || position == 10 || position == 11)) {
            outRect.bottom = space;
        }*/
    }

}